<?php
namespace Common\Model;

class AddressModel extends CommonModel{

    protected $_validate = array(
        array('name','require','请输入收货人姓名'),
        array('phone','require','请输入手机号'),
        array('phone','/1[3-8][0-9]{9}/','手机号格式有误'),
        array('area','require','请选择所在地区'),
        array('address','require','请输入详细地址'),
    );
    public function get_address($user_id,$address_id=null){
    	if(empty($user_id)) return false;
    	if((int)$address_id){
    		return $this->where(array('id'=>$address_id))->find();
    	}
    	$info = $this->where(array('user_id'=>$user_id,'is_default'=>'1'))->find();
    	if(empty($info))$info = $this->where(array('user_id'=>$user_id))->order('create_time asc')->find();
    	if(empty($info))return false;
    	return $info;
    }
}